package com.xcjh.smartchat.ui.login

import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import com.xcjh.base_lib.base.BaseViewModel
import com.xcjh.base_lib.bean.GoodsBean
import com.xcjh.base_lib.callback.livedata.BooleanLiveData
import com.xcjh.smartchat.net.apiService
import com.xcjh.base_lib.utils.request
import com.xcjh.smartchat.bean.UserInfo


class LoginVM : BaseViewModel() {
    var email = MutableLiveData("")
    var code = MutableLiveData("")

    private val _login = MutableLiveData<UserInfo>()
    val login get() = _login

    /**
     * 登陆按钮是否可点击
     */
    val loginEnableLiveData = BooleanLiveData()

    /**
     * 校验登录按钮是否可点击
     */
    fun checkLoginEnable(ph: String = email.value!!, pw: String = code.value!!) {
        if (TextUtils.isEmpty(ph) || TextUtils.isEmpty(pw)) {
            loginEnableLiveData.postValue(false)
            return
        }
        loginEnableLiveData.postValue(true)
    }


    //选择到的物品获取消耗品
    val goodsInfo = MutableLiveData<GoodsBean>()
    var dataArticle = MutableLiveData<MutableList<GoodsBean>>()
    var dataConsume = MutableLiveData<MutableList<GoodsBean>>()

    /**
     * 获取一般物品
     */
    fun getRoleArticle() {

        request(
            block = { apiService.selectRoleArticle() },
            success = {
                dataArticle.value = it
            },
            error = {
                val listDataUiState = arrayListOf<GoodsBean>(
                   /* GoodsBean(id = "0", serialNum = "0", name = "jjj"),
                    GoodsBean(id = "1", serialNum = "1", name = "aaa"),
                    GoodsBean(id = "2", serialNum = "2", name = "bbb"),
                    GoodsBean(id = "3", serialNum = "3", name = "ccc"),
                    GoodsBean(id = "4", serialNum = "4", name = "ddd"),
                    GoodsBean(id = "5", serialNum = "5", name = "eee"),
                    GoodsBean(id = "6", serialNum = "6", name = "fff"),
                    GoodsBean(id = "7", serialNum = "7", name = "ggg"),
                    GoodsBean(id = "8", serialNum = "8", name = "hhh"),
                    GoodsBean(id = "9", serialNum = "9", name = "iii"),
                    GoodsBean(id = "99", serialNum = "99", name = "777"),
                    GoodsBean(id = "999", serialNum = "999", name = "7788"),*/
                )

                dataArticle.value = listDataUiState
            },
        )

    }

}